package cn.java86.print;

/**
 * @author oldliu
 * @since 1.0
 */
//纸张，代表所有的纸张
//不同的纸张，设置的不同的属性
public class TextPaper {
    private int words;//一行几个字
    private int lines;//一页多少行

    public void print(String str) {
        char[] cr = str.toCharArray();
        //w是记录当前行打了几个字
        //l是当前纸张打印了几行
        //page是当前的页码
        int w = 0, l = 0;
        int page = 1;
        for (char c : cr) {
            System.out.print(c);
            w++;
            if (w >= words) {
                w = 0;
                l++;//一行到头换行
                System.out.println();
                if (l >= lines) {
                    //一张纸打完，要换纸
                    l = 0;
                    System.out.println("--" + page + "---");
                    page++;
                }
            }
        }
        if (l < lines) {
            System.out.println("\n--" + page + "---");
        }
    }

    public void setWords(int words) {
        this.words = words;
    }

    public void setLines(int lines) {
        this.lines = lines;
    }
}
